package com.epsoft.odin7cj.flow.bpo._impl.instance;

import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.history.HistoricProcessInstance;
import org.camunda.bpm.engine.runtime.ProcessInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.epsoft.odin7cj.flow.bpo.instance.InstanceBPO;
import com.epsoft.odin7cj.flow.model.instance.FlowInstance;

/**  
 * 审计任务BOP实现类 
 * @author 胡义振  
 * @date 2018年10月16日  
*/
@Service 
public class InstanceBPOImpl implements InstanceBPO {

	@Autowired
	private RuntimeService runtimeService;
	
	@Override
	public FlowInstance convertToInstance(ProcessInstance proIns) {
		
		FlowInstance flowInstance = new FlowInstance();
		if(flowInstance!=null) {
			flowInstance.setInstanceId(proIns.getId());
			flowInstance.setProcessInstanceId(proIns.getProcessInstanceId());
			flowInstance.setRootProcessInstanceId(proIns.getRootProcessInstanceId());
			flowInstance.setCaseInstanceId(proIns.getCaseInstanceId());
			flowInstance.setInstanceParams(runtimeService.getVariables(proIns.getId()));
			flowInstance.setBusinessKey(proIns.getBusinessKey());
			flowInstance.setDefinitionId(proIns.getProcessDefinitionId());
			flowInstance.setStartUserId(proIns.getTenantId());
		}
		return flowInstance;
	}
	
	

	@Override
	public FlowInstance convertToHistoricProcessInstance(HistoricProcessInstance proIns) {
		FlowInstance flowInstance = new FlowInstance();
		if(flowInstance!=null) {
			flowInstance.setInstanceId(proIns.getId());
			flowInstance.setRootProcessInstanceId(proIns.getRootProcessInstanceId());
			flowInstance.setCaseInstanceId(proIns.getCaseInstanceId());
			flowInstance.setInstanceParams(runtimeService.getVariables(proIns.getId()));
			flowInstance.setBusinessKey(proIns.getBusinessKey());
			flowInstance.setDefinitionId(proIns.getProcessDefinitionId());
			flowInstance.setStartUserId(proIns.getTenantId());
		}
		return flowInstance;
	}


}
